/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Main;

import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author anas
 */
public class Client extends javax.swing.JInternalFrame {

    
    Connection conn= null;
    ResultSet rs = null;
    PreparedStatement ps =null;
    
    public Client() {
        initComponents();
        conn = gestion_chambres.Gestion_Chambres.DB_Connection();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        CIN_Client = new javax.swing.JTextField();
        Nom_Client = new javax.swing.JTextField();
        Prenom_Client = new javax.swing.JTextField();
        Numero_Tele_Client = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        Email_Client = new javax.swing.JTextField();
        Metier_Client = new javax.swing.JTextField();
        Nombre_Enfant_Client = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        oui = new javax.swing.JRadioButton();
        non = new javax.swing.JRadioButton();
        Date_Naissance_Client = new com.toedter.calendar.JDateChooser();
        Enregistrer = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setClosable(true);
        setMaximizable(true);
        setResizable(true);

        jLabel2.setText("Nom :");

        jLabel3.setText("Prénom :");

        jLabel4.setText("N° Tele : ");

        jLabel1.setText("CIN  :");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(295, 295, 295)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(66, 66, 66)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(CIN_Client)
                    .addComponent(Nom_Client)
                    .addComponent(Prenom_Client)
                    .addComponent(Numero_Tele_Client, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(479, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(71, 71, 71)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(CIN_Client, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(46, 46, 46)
                        .addComponent(jLabel2))
                    .addComponent(Nom_Client, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(56, 56, 56)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(Prenom_Client, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(65, 65, 65)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(Numero_Tele_Client, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(95, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(" Obligatoire Infos", jPanel1);

        jLabel5.setText("Email :");

        jLabel6.setText("Marié : ");

        jLabel7.setText("Métier :");

        jLabel8.setText("Date de Naissance :");

        Metier_Client.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Metier_ClientActionPerformed(evt);
            }
        });

        jLabel9.setText("Nombre d'enfants :");

        buttonGroup1.add(oui);
        oui.setText("Oui");

        buttonGroup1.add(non);
        non.setText("Non");

        Date_Naissance_Client.setDateFormatString(" YYYY-MM-dd");

        Enregistrer.setText("Enregistrer");
        Enregistrer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EnregistrerActionPerformed(evt);
            }
        });

        jButton2.setText("Annuler");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(164, 164, 164)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(228, 228, 228)
                        .addComponent(jButton2)
                        .addGap(18, 18, 18)
                        .addComponent(Enregistrer)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(87, 87, 87)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel5))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 164, Short.MAX_VALUE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel8))
                                .addGap(99, 99, 99)))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(Email_Client, javax.swing.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)
                            .addComponent(Metier_Client)
                            .addComponent(Nombre_Enfant_Client)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(oui)
                                .addGap(18, 18, 18)
                                .addComponent(non))
                            .addComponent(Date_Naissance_Client, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(410, 410, 410))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(Email_Client, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(40, 40, 40)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(oui)
                    .addComponent(non))
                .addGap(33, 33, 33)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(Metier_Client, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(jLabel8)
                        .addGap(41, 41, 41))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Date_Naissance_Client, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(Nombre_Enfant_Client, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Enregistrer)
                    .addComponent(jButton2))
                .addGap(16, 16, 16))
        );

        jTabbedPane1.addTab("Optionnel infos", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
        private String  Status_Client()
        {
            String marier ="";
                if(oui.isSelected())
                {
                    return  "Marié";
                }
                else if(non.isSelected()) {
                    return "non marié";
                }
                else{
                
                    JOptionPane.showMessageDialog(null, "Error");
                }
        return null;
                
                
        }
        private void Get_Info()
        {
        
               
               
               
        
        }
    
    
    
    private void Metier_ClientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Metier_ClientActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Metier_ClientActionPerformed
    
    private void EnregistrerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EnregistrerActionPerformed
       
        
               /* String cin = CIN_Client.getText();
                String nom = Nom_Client.getText();
                String prenom =Prenom_Client.getText();
                String email = Email_Client.getText();
                String num_tele =Numero_Tele_Client.getText();
                String metier = Metier_Client.getText();
                //Date date_naissance =Date_Naissance_Client.getDate();
                String nombre_enfants = Nombre_Enfant_Client.getText();*/
                
                
                
                // marriage
                
        //la reservation 
                
                   //int nmbre_enfants =Integer.parseInt(Nombre_Enfant_Client.getText());
                
                try{
                         
                        String sql1 ="insert into CLIENT(CIN_CLIENT,NOM,PRENOM,NUMERO_TELE,EMAIL,SITUATION,DATE_NAISSANCE,METIER,NOMBRE_ENFANTS) values(?,?,?,?,?,?,?,?,?)";
                        
                        //String sql3="insert into CHAMBRE(CIN_CLIENT) values(?)";
                        //String sql4="insert into PAIEMENT(CIN_CLIENT) values(?)"; 
                   
                        // inserer au table CLIENT
                        PreparedStatement ps1 = conn.prepareStatement(sql1); 
                        ps1.setString(1, CIN_Client.getText());
                        ps1.setString(2, Nom_Client.getText());
                        ps1.setString(3, Prenom_Client.getText());
                        ps1.setString(4, Numero_Tele_Client.getText());
                        ps1.setString(5, Email_Client.getText());
                        ps1.setString(6, Status_Client());
                        ps1.setString(7, ((JTextField)Date_Naissance_Client.getDateEditor().getUiComponent()).getText());
                        ps1.setString(8, Metier_Client.getText());
                       
                        ps1.setInt(9, Integer.parseInt(Nombre_Enfant_Client.getText()));
                        // Insertion dans la table CHAMBRE
                       /* PreparedStatement ps3 = conn.prepareStatement(sql3); 
                        ps3.setString(1, CIN_Client.getText());
                        
                        
                        // Insertion dans la table PAIEMENT
                        PreparedStatement ps4 = conn.prepareStatement(sql4); 
                        ps4.setString(1, CIN_Client.getText());
                        */
                        
                        //execution des requetes
                        ps1.executeUpdate();
                        //ps2.executeUpdate(sql2);
                        //ps3.executeUpdate(sql3);
                        //ps4.executeUpdate(sql4);
                        
                        JOptionPane.showMessageDialog(null,"Les information a enregistrer avec succes");
                        
                        
                }catch(SQLException | HeadlessException e)
                {
                    
               JOptionPane.showMessageDialog(null,"Echec d'Insertion Client "+""+e.getMessage());  
                    
                }
                
                
                
        
    }//GEN-LAST:event_EnregistrerActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JTextField CIN_Client;
    public static com.toedter.calendar.JDateChooser Date_Naissance_Client;
    public static javax.swing.JTextField Email_Client;
    private javax.swing.JButton Enregistrer;
    public static javax.swing.JTextField Metier_Client;
    public static javax.swing.JTextField Nom_Client;
    public static javax.swing.JTextField Nombre_Enfant_Client;
    public static javax.swing.JTextField Numero_Tele_Client;
    public static javax.swing.JTextField Prenom_Client;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTabbedPane jTabbedPane1;
    public static javax.swing.JRadioButton non;
    public static javax.swing.JRadioButton oui;
    // End of variables declaration//GEN-END:variables
}
